<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../assets/css/layui.css" />
		<script src="../assets/layui.js" type="text/javascript" charset="utf-8"></script>

		<link rel="stylesheet" type="text/css" href="../js/bootstarp-3.3.7/css/bootstrap.min.css" />
		<script src="../js/jquery/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>

		<link rel="stylesheet" type="text/css" href="../js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
		<script src="../js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>

	</head>
	<script>
		$(function() { //, headers: { 'x-requested-with': 'XMLHttpRequest' }
			$.ajaxSetup({
				crossDomain: true,
				xhrFields: {
					withCredentials: true
				}
			});
		});
	</script>
	<script type="text/javascript">
		var id = new Array();
		var id2 = new Array();          

		layui.use(['element', 'layer'], function() {
			var $ = layui.jquery,
				layer = layui.layer,
				element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
  
			$(function() { 
				$.ajax({
					type: "post", 
					url: "http://localhost:8091/queryMedicines",
					success: function(data) {
						var namestr = "";
						for(var i = 0; i < data.length; i++) {
							if(data[i].early_warning >= data[i].inventory_num) {
								namestr += data[i].medicines_name + ",";
							}
						} 
						if(namestr != "") {
							namestr += "这些药品出现库存警告，请尽快联系工作人员进药";
							layer.msg(namestr, {
								time: '4000',
								icon: 2,
								title: '库存预警',
								btn: '明白了',
								anim: 6,
							});
						}
					}
				});

				$("#btn").click(function() {

					$("#zycf").bootstrapTable('refresh')
				})

				$("#btn2").click(function() {
					$("#jcxm").bootstrapTable('refresh')

				})

				$("#zycf").bootstrapTable({
					url: "http://localhost:8091/ChineseMedicines",
					pagination: true,
					pageSize: 5,
					queryParams: queryParams,
					clickToSelect: true,
					columns: [{
						checkbox: true,
						width: 80,
					}, {
						field: 'medicines_name',
						title: '名称',
						align: 'center',
						valign: 'middle',
					}, {
						field: 'unit',
						title: '规格',
						align: 'center',
						valign: 'middle',
					}, {
						field: 'inventory_num',
						title: '库存',
						align: 'center',
						valign: 'middle',
					}, {
						field: 'inventory_prescription_price',
						title: '单价',
						align: 'center',
						valign: 'middle',
					}, {
						field: 'early_warning',
						title: '预警数量',
						align: 'center',
                        valign: 'middle',
					}]

				})

				$("#jcxm").bootstrapTable({
					url: "http://localhost:8091/Check_Project",
					pagination: true,
					pageSize: 5,
					queryParams: queryParams2,
					clickToSelect: true,
					columns: [{
						checkbox: true,
						width: 80,
					}, {
						field: 'inspection_name',
						title: '项目名称',
						align: 'center',
						valign: 'middle',
					}, {
						field: 'unit_price',
						title: '单价',
						align: 'center',
						valign: 'middle',
					}, {
						field: 'unit',
						title: '最小单位',
						align: 'center',
						valign: 'middle',
					}]
				})

				//				$("#allChoose").click(function(){
				//					$(".drug").each(function(){
				//						
				//						if ($(this).attr("checked")!="checked") {
				//							$(this).attr("checked","checked");
				//						}else{
				//							$(this).attr("checked",false);
				//						}
				////						alert()''
				//						
				//					})
				//					
				//					
				//				})

				$("#addDrugBtn").click(function() {
					id.splice(0, id.length)
					var getSelectRows = $("#zycf").bootstrapTable('getSelections', function(row) {
						return row;
					});
					for(var i = 0; i < getSelectRows.length; i++) {
						id.push(getSelectRows[i].medicines_id);
					}

					//					var idstr = id.join(",");
					//					alert(id)
					parent.$("#drugIdStr").val(id)
					
					
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
					
					

				})
				
				$("#addCfBtn").click(function(){
					id2.splice(0,id2.length)
					var getSelectRows2 = $("#jcxm").bootstrapTable('getSelections', function(row) {
						return row;
					});
					for(var i = 0; i < getSelectRows2.length; i++) {
						id2.push(getSelectRows2[i].ins_id);
//						alert(getSelectRows2[i].ins_id)
					}
					
					parent.$("#cfIdStr").val(id2)
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				})
			})

			function queryParams(Params) {

				return {
					'medicines_name': $("#cfname").val()

				}
			}

			function queryParams2(Params) {
				//			alert($("#projectname").val())
				return {
					'inspection_name': $("#projectname").val()

				}
			}

		})
	</script>

	<body>

		<div class="layui-tab layui-tab-card">
			<ul class="layui-tab-title">
				<li class="layui-this" style="width: 50%;">中药处方</li>
				<li style="width: 50%;">检查项目</li>

			</ul>
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show" align="center">
					<form class="form-inline">
						<label for="exampleInputName2">药品名称：</label>
						<input type="text" class="form-control" name="name" id="cfname" value="" placeholder="请输入药品名称" />
						<button type="button" class="btn btn-primary glyphicon glyphicon-search" id="btn"></button>
						<button type="button" class="btn btn-danger glyphicon glyphicon-ok" id="addDrugBtn"></button>
					</form>
					<br />
					<div>
						<table id="zycf"></table>
					</div>

				</div>

				<div class="layui-tab-item" align="center">
					<form class="form-inline">
						<label for="exampleInputName2">项目名称：</label>
						<input type="text" class="form-control" name="" id="projectname" value="" placeholder="请输入项目名称" />
						<button type="button" class="btn btn-primary glyphicon glyphicon-search" id="btn2"></button>
						<button type="button" class="btn btn-danger glyphicon glyphicon-ok" id="addCfBtn"></button>

					</form>
					<br />
					<div>
						<table id="jcxm"></table>
					</div>

				</div>

			</div>
		</div>
	</body>

</html>